package com.wlyuan.open.remote.facade;

import com.wlyuan.basic.api.IGoodsService;
import com.wlyuan.basic.dto.goods.GoodsCreationDTO;
import com.wlyuan.basic.dto.goods.GoodsDetailDTO;
import com.wlyuan.open.dto.order.OrderGoodsCreateDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.var;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author yuanjie
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class GoodsFacade {
    @Resource
    private IGoodsService goodsService;

    public GoodsDetailDTO createGoods(OrderGoodsCreateDTO goodsDTO, Long customerId, Long tenantId, Long userId) {
        var creation = new GoodsCreationDTO();
        BeanUtils.copyProperties(goodsDTO, creation);
        creation.setGoodsTypeId(null);
        creation.setBarcode(goodsDTO.getMaterialCode());
        creation.setType(goodsDTO.getGoodsTypeName());
        creation.setName(goodsDTO.getGoodsName());
        creation.setCustomerId(customerId);
        creation.setNetWeight(goodsDTO.getWeight());
        creation.setTenantId(tenantId);
        creation.setUserId(userId);
        if (StringUtils.isBlank(creation.getSpec())) {
            creation.setSpec("#");
        }
        return goodsService.createShould(creation, true);

    }
}
